package com.llamarun;

import java.util.Random;

import android.util.Log;
import android.view.View;

public class GameObjectFactory {
	Random generator;
	//probability that gameobject creates a new object
	double probOfNewObject = .05;
	GameView view;
	
	public GameObjectFactory(GameView gameView)
	{
	    generator = new Random();	
	    view = gameView;
	}
	
	public GameObject createGameObject()
	{
		double randNum = generator.nextDouble();
		int total = Enemy.probabilityScore() + PowerUp.probabilityScore() + Projectible.probabilityScore();
		double probOfEnemy = (double) Enemy.probabilityScore()/total;
		double probOfProjectible = (double) Projectible.probabilityScore()/total;
		if(randNum <= probOfNewObject)
		{
			randNum = generator.nextDouble();
			//create an enemy!
			if(randNum <= probOfEnemy)
			{
				return createNewEnemy();
				
			}
			//create a projectible!
			else if ((randNum > probOfEnemy) && (randNum <= probOfProjectible+probOfEnemy))
			{
				return createNewProjectible();	
			}
			//create a power up!
			else
			{
				return createNewPowerUp();
			}
		}
		//no game object gets created
		else
		{
			return null;
		}
	}
	
	public GameObject createNewEnemy()
	{
		int randInt = generator.nextInt(3);
		switch (randInt)
		{
		case 0:
			return new Farmer(view);
		case 1:
			return new Wolf(view);
		case 2:
			return new Shmorphon(view);
		default:
			return null;
		}		
	}
	
	public GameObject createNewProjectible()
	{
		int randInt = generator.nextInt(4);
		switch (randInt)
		{
		case 0:
			return new Brick(view);
		case 1:
			return new Potato(view);
		case 2:
			return new Sheep(view);
		case 3:
			return new Duck(view);
		default:
			return null;
		}			
	}
	
	public GameObject createNewPowerUp()
	{
		int randInt = generator.nextInt(3);
		switch (randInt)
		{
		case 0:
			return new Pizza(view);
		case 1:
			return new Mushroom(view);
		case 2:
			return new Star(view);
		default:
			return null;
		}		
	}
}
